<?

class Vakanz_Relation extends Vakanz_CRM_Db_Table_Row {
	protected $_prefix = 'relation';

	function isExisting() {
		return false;
	}
	public function save() {
		if ($this->offsetGet(current($this->getTable()->info('primary'))) > 0) {
			$this->relation_valid_till = date('Y-m-d H:i:s');
			$this->relation_status = 3;
			$data = $this->toArray();
			parent::save();
			unset($data[$this->_prefix.'_autoid']);
			unset($data[$this->_prefix.'_valid_till']);
			unset($data[$this->_prefix.'_valid_from']);
			unset($data[$this->_prefix.'_status']);
			$relation = $this->getTable()->createRow($data);
			$relation_autoid = $relation->save();
			return $relation_autoid;
		} else {
			if (empty($this->relation_id)) {
				$this->relation_id = $this->getTable()->getNewId('relation_id');
			}
			return parent::save();
		}
	}
	public function delete() {
		$this->relation_valid_till = date('Y-m-d H:i:s');
		$this->relation_status = 5;
		parent::save();
		
	}
	/**
	 *
	 *
	 */
	public function getRelationMeta() {
		$relationMetas = new Vakanz_Relation_Metas();
		$query = $relationMetas->select()->where('relationmeta_status = ? ', 10);
		$rs = $this->findVakanz_Relation_Metas($query);
		return $rs->current();
	}
	
	public function getRelationYears() {
		$rs = $this->findVakanz_Relation_Years();
		return $rs;
	}
	
}